package exam01sellTicket;

public class MyThread extends Thread{
    static int total;

    public MyThread(String name) {
        super.setName(name);
    }

    @Override
    public void run() {
        while (true){
            synchronized (MyThread.class){
                if (total == 0){
                    break;
                }
                total --;
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println(getName() + "还剩" + total +"张");
            }
        }
    }
}
